<?php

declare(strict_types=1);
namespace app\common\business;


use app\common\lib\Num;
use app\common\lib\sms\ZhenziSmsClient;

class Sms
{
    public static function sendCode(String $phone_number,int $len) : bool{
        $code = Num::getCode($len);

        $client = new ZhenziSmsClient('https://sms_developer.zhenzikj.com','105100','243a8ef8-0335-4e06-9e71-26866205c1cb');
        $params = array('message'=>'验证码为: '.$code,'number'=>$phone_number);
        $result = json_decode($client->send($params));
        if($result->code == 0){
            // 根据手机号查询验证码， 失效时间
            // redis 扩展
            // redis 服务
            cache(config('redis.code_pre').$phone_number,$code,config('redis.code_expire'));
            return true;
        }
        else{
            return false;
        }
    }
}